package com.smartboot.plus.ignite.listener;

import com.smartboot.plus.holder.BrokerContextHolder;
import org.apache.ignite.lang.IgniteBiPredicate;
import tech.smartboot.feat.core.common.logging.Logger;
import tech.smartboot.feat.core.common.logging.LoggerFactory;
import tech.smartboot.mqtt.plugin.spec.MqttSession;

import java.io.Serializable;
import java.util.UUID;

public class DisconnectMessage implements IgniteBiPredicate<UUID, Object>, Serializable {
    private static final Logger LOGGER = LoggerFactory.getLogger(DisconnectMessage.class);


    @Override
    public boolean apply(UUID uuid, Object msg) {
        MqttSession session = BrokerContextHolder.get().getSession(msg.toString());
        if (session != null) {
            session.disconnect();
            LOGGER.warn("Received disconnect  clientId: " + msg);
        }
        return true;
    }
}
